import React from 'react'
import { message, Modal, Select } from 'antd';
import { Button, Checkbox, Form, Input } from 'antd';
import { fastSend } from './service'
const FastCardModel = ({ SendCard, isModalOpen, setIsModalOpen }) => {

    const [form] = Form.useForm();
    const onFinish = values => {
        console.log('Success:', values);
        form.validateFields().then(() => {
            fastSend(values.lock_type, values.lock_number).then(res => {
                console.log(res)

                if (res.code == 0) {
                    SendCard({
                        locker_number: values.lock_number,
                        physical_zone: res.data.physical_zone
                    }).then(res => {

                        if (res.code == 0) {
                            form.setFieldsValue({
                                lock_number: parseInt(values.lock_number) + 1
                            })
                        }
                    })
                } else {
                    message.error(res.msg)
                }
                // setIsModalOpen(false)    
            })
        }).catch(() => {
            console.log('error')
        })
    };

    return (
        <Modal
            title="快速发卡"
            closable={{ 'aria-label': 'Custom Close Button' }}
            visible={isModalOpen}
            form={form}
            onCancel={() => setIsModalOpen(false)}
            footer={[
                <Button key="submit" type="primary" htmlType="submit" onClick={() => { form.submit() }}>
                    确定
                </Button>,
            ]}
        >
            <Form
                name="basic"
                labelCol={{ span: 6 }}
                wrapperCol={{ span: 16 }}
                style={{ maxWidth: 600 }}
                onFinish={onFinish}
                onKeyDown={(e) => {
                    if (e.key === 'Enter') {
                        e.preventDefault();
                        e.currentTarget.dispatchEvent(
                            new Event('submit', { cancelable: true, bubbles: true })
                        );
                    }
                }}
                form={form}
            >
                <Form.Item
                    label="柜号"
                    name="lock_number"
                    rules={[{ required: true, message: '请输入开始柜号!' }]}
                >
                    <Input placeholder="请输入开始柜号" style={{fontSize: '18px',fontWeight: 'bold'}} />
                </Form.Item>

                <Form.Item
                    label="柜类型"
                    name="lock_type"
                    rules={[{ required: true, message: '请选择柜类型!' }]}
                    initialValue={'更衣柜'}
                >
                    <Select
                        options={[
                            { value: '鞋柜', label: '鞋柜' },
                            { value: '更衣柜', label: '更衣柜' },
                        ]}
                    >

                    </Select>
                </Form.Item>



            </Form>
        </Modal>
    )
}

export default FastCardModel